import actions from '../constant'

const initialState = {
  user: {},
  isFetch: false,
  error: null
}

const user = (state = initialState, action) => {
  switch(action.type) {
    case actions.SIGNIN:
      return {
        user: action.user,
        isFetch: false,
        error: null
      }
    case actions.BEFORE_FETCH:
      return {
        user: {},
        isFetch: true,
        error: null
      }
    case actions.FAIL_FETCH:
      return {
        user: {},
        isFetch: false,
        error: action.error
      }
    default:
      return state
  }
}

export default user